from typing import List


# 剑指 Offer 42. 连续子数组的最大和
class Solution:
    def maxSubArray(self, nums: List[int]) -> int:
        if len(nums) < 2:
            return nums[0]
        max_sum = nums[0]
        temp = [x for x in nums]
        for j in range(1, len(temp)):
            if temp[j-1] > 0:
                temp[j] = temp[j] + temp[j-1]
            if max_sum < temp[j]:
                max_sum = temp[j]
        return max_sum


if __name__ == '__main__':
    t = [-2, 1]
    s = Solution()
    print(s.maxSubArray(t))
